package com.fy.fyzf.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.zhouwei.library.CustomPopWindow;
import com.fy.fyzf.R;
import com.fy.fyzf.bean.PriceFilterBean;

import java.util.ArrayList;
import java.util.List;

import ui.adapter.PriceFilterAdapter;

public class PriceFilterPopwindow {
    private Context mContext;
    View popView;
    List<PriceFilterBean> priceList;
    PriceFilterAdapter priceFilterAdapter;
    public PriceFilterPopwindow(Context context) {
        mContext = context;
        initView();
    }

    private void initView() {
        priceList = new ArrayList<>();
        priceList.add(new PriceFilterBean("全部", null));
        priceList.add(new PriceFilterBean("3元以下", 1));
        priceList.add(new PriceFilterBean("3—4元", 2));
        priceList.add(new PriceFilterBean("4—5元", 3));
        priceList.add(new PriceFilterBean("5—6元", 4));
        priceList.add(new PriceFilterBean("6元以上", 5));


    }

    CustomPopWindow customPopWindow;
    private int selectPo = -1;

    public int getSelectPo() {
        return selectPo;
    }

    public void setSelectPo(int selectPo) {
        this.selectPo = selectPo;
    }

    public void showPop(View view) {
        popView = LayoutInflater.from(mContext).inflate(R.layout.popwindow_pricew_filter, null, false);
        customPopWindow= new CustomPopWindow.PopupWindowBuilder(mContext).setView(popView)
                .size(ViewGroup.LayoutParams.MATCH_PARENT, 1000)
                .setFocusable(true)
                .setOutsideTouchable(false)
                .enableBackgroundDark(true)
                .create()//创建PopupWindow
                .showAsDropDown(view,0,-10);

        popView.findViewById(R.id.ll_unuseable).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                customPopWindow.dissmiss();
            }
        });
        RecyclerView recyclerView = popView.findViewById(R.id.recycleView);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        priceFilterAdapter = new PriceFilterAdapter();
        recyclerView.setAdapter(priceFilterAdapter);
        priceFilterAdapter.setNewData(priceList);

        priceFilterAdapter.setSelect(selectPo);
    }
    public PriceFilterAdapter getPriceFilterAdapter(){
        return priceFilterAdapter;
    }
    public View getView(int viewId){
        return popView.findViewById(viewId);
    }

    public void onDismiss(){
        if (null != customPopWindow) {
            customPopWindow.dissmiss();
        }
    }
}
